var express = require('express');
var router = express.Router();
var query = require("./Database");
/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('ProPwd', {});
});
router.post('/changepass',async (req,res)=>{
    console.log("--------------");
    console.log(req.body);
    let list = req.body;
    let rows = await query("select * from users where id = "+ list.id+" and phone = "+list.phone);
    console.log(rows);
    if (rows.length>0&&rows[0].password!=list.password){
        let rowword = await query("update users set password ="+list.password+" where id = "+ list.id+" and phone = "+list.phone);
        console.log(rowword);
        let data = {code:200};
        res.send(data);
    console.log(rowword.message);
    }else if (rows.length>0&&rows[0].password==list.password) {
        let data = {code:100};
        res.send(data);
    }else {
        let data = {code:0};
        res.send(data);
    }
});
module.exports = router;